<template>
    <div class="qingtingfm" :style="{minHeight:h+'px'}">
        <div class="qingtingdiv">
          <upload-excel-component @on-selected-file="exportData" buttonName="导入兑换码"></upload-excel-component>
          <upload-excel-component @on-selected-file="exportData" buttonName="导入领取手机号"></upload-excel-component>
        </div>

    </div>
</template>

<script>
    import UploadExcelComponent from "@/components/UploadExcel/index.vue";
    import axios from "axios";
    export default{
    	components: {
    		UploadExcelComponent
    	},
    	name: 'qingtingfm',
    	data(){
    		return{
    			h:"",
          list:[],
          hreflist:[]
    		}
    	},
    	created() {
    		var h = document.documentElement.clientHeight;
    		this.h = h;
    	},
        methods:{
            //导入
            exportData:function(data) {
                console.log(data)
                var list = []
                var hreflist = []
                //导入福利
                if(data.header[0] == '兑换码'){
                    for(var i = 0 ;i < data.results.length; i++){
                          list.push(
                              {"data":data.results[i]['兑换码'],"source":data.results[i]['类目']}
                          )
                    }
                    this.list = list
                    this.hreflist = hreflist
                    axios.post('/api/plan-market/benefits/import',{data:this.list})
                    	.then(response => {
                    		if(response.data.msg.code == 0){
                                this.$message({
                                  message: '导入成功！',
                                  type: 'success'
                                });
                            }else{
                                this.$message.error(response.data.msg.info);
                            }
                    	})
                }
                //导入手机号
                if(data.header[0] == 'mobile'){
                    for(var i = 0 ;i < data.results.length; i++){
                          list.push(
                              {"mobile":data.results[i]['mobile'],"source":data.results[i]['class'],"times":data.results[i]['times']}
                          )
                    }
                    this.list = list
                    this.hreflist = hreflist
                    axios.post('/api/plan-market/benefit/logs/import',{data:this.list})
                    	.then(response => {
                    		if(response.data.msg.code == 0){
                                this.$message({
                                  message: '导入成功！',
                                  type: 'success'
                                });
                            }else{
                                this.$message.error(response.data.msg.info);
                            }
                    	})
                }
            }
        }
    }
</script>

<style lang="scss" scoped>
	.qingtingfm{
		margin: 0; padding: 0; background: #EFEFEF; display: flex; justify-content: center; align-items: center;
		.el-button--primary{ background: #409EFF !important; border: 1px #409EFF solid !important;}
    .qingtingdiv{
      div{ margin: 20px 0;}
    }
	}
</style>